@import '../../styles/common';
@import '../../styles/mixins/listbox';
@import '../../Button/styles/index';
@import '../../internals/Picker/styles/mixin';

// Calendar panel
// ----------------------

.rs-calendar {
  padding-top: @calendar-picker-padding;
  position: relative;
  min-height: 266px;
  overflow: hidden;

  &-bordered &-table {
    border: 1px solid var(--rs-border-primary);
    border-radius: @calendar-panel-border-radius;
  }

  &-bordered &-table-row:not(:last-child) &-table-cell,
  &-bordered &-table-header-row &-table-header-cell {
    border-bottom: 1px solid var(--rs-border-secondary);
  }

  &-bordered &-month-dropdown {
    border: 1px solid var(--rs-border-primary);
    border-radius: @calendar-panel-border-radius;
  }

  &-panel &-header {
    width: 100%;
    padding-bottom: 6px;
    .clearfix();
  }

  &-panel &-header &-btn-today {
    float: right;
  }

  &-panel &-header-forward,
  &-panel &-header-backward {
    float: none !important;
  }

  &-panel&-month-view &-header-forward,
  &-panel&-month-view &-header-backward {
    display: inline-block;
    visibility: hidden;
    pointer-events: none;
  }

  &-panel &-header-month-toolbar {
    width: auto !important;
  }

  &-panel&-month-view &-header-month-toolbar {
    padding-left: 0;
    padding-right: 0;
  }

  &-panel &-month-view {
    padding-left: 0;
    padding-right: 0;
  }

  &-panel &-table-header-row &-table-header-cell-content {
    padding-top: 8px; // padding + border = 10px
    padding-bottom: 8px;
  }

  &-panel &-table-cell-is-today &-table-cell-day {
    color: var(--rs-calendar-today-text);
    width: @calendar-panel-today-active-side-length;
    height: @calendar-panel-today-active-side-length;
    background-color: var(--rs-calendar-today-bg);
    border-radius: 50%;
    margin-left: auto;
    margin-right: auto;
  }

  &-panel &-table-cell-is-today &-table-cell-content {
    box-shadow: none;
  }

  &-panel &-table-cell-selected &-table-cell-content {
    background-color: inherit;
    color: inherit;
    box-shadow: inset 0 0 0 1px var(--rs-input-focus-border);
  }

  &-panel &-table-cell-day {
    margin-top: 3px;
    display: block;
    text-align: center;
  }

  &-panel &-month-dropdown {
    margin-top: -2px;
    margin-left: 12px;
    margin-right: 12px;
    top: 54px;
    width: ~'calc(100% - 24px)';
  }

  &-panel:not(&-compact) &-month-dropdown-scroll {
    height: 644px; // Flow design
  }

  &-panel&-compact &-month-dropdown-scroll {
    height: 344px; // Flow design
  }

  &-panel:not(&-compact) &-table-row:not(&-table-header-row) &-table-cell-content {
    width: 100%;
    height: @calendar-panel-cell-height;
    overflow: hidden;
  }

  &-panel:not(&-compact) &-table-cell {
    vertical-align: top;
  }

  &-panel &-table-cell {
    padding: 0 1px;
    line-height: 0;
  }

  &-panel &-table-cell-content {
    width: 100%;
    border-radius: 0;
  }

  &-panel &-table-row:last-child :first-child &-table-cell-content {
    border-bottom-left-radius: @calendar-panel-border-radius;
  }

  &-panel &-table-row:last-child :last-child &-table-cell-content {
    border-bottom-right-radius: @calendar-panel-border-radius;
  }

  &-panel&-compact &-table-row:not(&-table-header-row) &-table-cell-content {
    height: @calendar-panel-compact-cell-height;
  }

  &-btn-close {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 14px;
    padding: 0;
    border: 0;
    display: flex;
    justify-content: center;
    background: var(--rs-bg-overlay);
    z-index: 1;
  }

  &-panel &-btn-close {
    bottom: 11px;
    margin: 0 20px;
  }
}

// DatePicker
// ----------------------

// Show month dropdown
.rs-calendar-month-view {
  .rs-calendar-header-month-toolbar {
    padding-left: 24px;
    padding-right: 24px;
  }

  .rs-calendar-header-backward,
  .rs-calendar-header-forward {
    display: none;
  }

  .rs-calendar-header-title-date {
    .picker-calendar-title-show();

    &.rs-calendar-header-error {
      color: var(--rs-text-error);

      &:focus,
      &:hover:active {
        color: #fff !important;
      }
    }
  }
}

// Show time dropdown
.rs-calendar-time-view {
  .rs-calendar-header-title-time {
    .picker-calendar-title-show();

    &.rs-calendar-header-error {
      color: var(--rs-text-error);

      &:hover:active {
        color: #fff;
      }
    }
  }
}

// Calendar group
.rs-calendar-table-cell-selected,
.rs-calendar-table-cell-in-range {
  position: relative;

  &::before {
    content: '';
    display: block;
    width: 100%;
    margin-top: 4px;
    height: 24px;
    position: absolute;
    z-index: @zindex-date-range-picker-table-cell-content - 1;
    top: 0;
  }

  .rs-calendar-table-cell-content {
    z-index: @zindex-date-range-picker-table-cell-content;
    position: relative;
  }
}

.rs-calendar-table-cell-in-range::before {
  background-color: var(--rs-calendar-range-bg);
}

.rs-calendar-table-cell-in-range:hover::before {
  display: none;
}

// Reset outline for scroll list.
.rs-calendar-month-dropdown-scroll div:focus {
  outline: none;
}

.rs-calendar-header {
  width: @calendar-header-width;
  padding-left: @calendar-picker-padding;
  padding-right: @calendar-picker-padding;
  .clearfix();

  // Month toolbar && Time toolbar
  &-month-toolbar,
  &-time-toolbar {
    display: inline-block;
  }

  &-month-toolbar {
    float: left;
  }

  &-time-toolbar {
    float: right;
  }

  &-title {
    margin: 0 @calendar-header-title-margin;
  }

  &-meridian {
    // Designer think it's nice!
    font-size: @font-size-small;
    margin-left: 4px;
  }

  &-error {
    .btn-error();
  }

  &-btn-disabled {
    &,
    &:hover,
    &:hover:focus {
      cursor: not-allowed;
      opacity: 0.3;
      background: none;
    }

    &::after {
      display: none !important;
    }
  }

  // Only Has month
  &-has-month:not(&-has-time) {
    margin: 0 auto;
    padding-left: @calendar-picker-padding;
    padding-right: @calendar-picker-padding;
  }

  &-has-month:not(&-has-time) &-month-toolbar {
    display: block;
    text-align: center;
    width: 100%;
    .clearfix();
  }

  &-has-month:not(&-has-time) &-backward {
    float: left;
  }

  &-has-month:not(&-has-time) &-forward {
    float: right;
  }

  // Only Has time
  &-has-time:not(&-has-month) {
    margin: 0 auto;
    text-align: center;
  }

  &-has-time:not(&-has-month) &-time-toolbar {
    float: none;
    display: inline-block;
  }

  // Has month && time
  &-has-month&-has-time {
    margin: 0 auto;
  }
}

/* rtl:begin:ignore */
/* stylelint-disable-next-line */
[dir='rtl'] .rs-calendar-header {
  &-backward,
  &-forward {
    .rs-icon {
      transform: rotate(180deg);
    }
  }
}

/* rtl:end:ignore */

.rs-calendar-body {
  padding: @calendar-picker-view-padding-top @calendar-picker-padding @calendar-picker-padding;
}

// Calendar Table
// TODO-Doma Use CSS grid layout.
.rs-calendar-table {
  display: table;
  table-layout: fixed;
  width: 100%;
}

.rs-calendar-table-row {
  display: table-row;

  &:nth-child(2) {
    .rs-calendar-table-cell-week-number {
      border-top-left-radius: @calendar-panel-border-radius;
      border-top-right-radius: @calendar-panel-border-radius;
    }
  }

  &:last-child {
    .rs-calendar-table-cell-week-number {
      border-bottom-left-radius: @calendar-panel-border-radius;
      border-bottom-right-radius: @calendar-panel-border-radius;
    }
  }
}

.rs-calendar-table-cell,
.rs-calendar-table-header-cell {
  display: table-cell;
  width: 1%;
  padding: @calendar-table-cell-padding 0;
  text-align: center;
  vertical-align: middle;

  &-un-same-month &-content,
  &-disabled &-content {
    &,
    &:hover {
      color: var(--rs-text-disabled);
    }
  }

  &-disabled &-content {
    &,
    &:hover {
      background: none;
      text-decoration: line-through;
      cursor: not-allowed;
    }
  }

  &-disabled&-is-today&-selected &-content {
    &:hover {
      .picker-calendar-cell-content-selected();
    }
  }

  &-disabled&-selected &-content {
    opacity: 0.3;
  }
}

.rs-calendar-table-cell-content {
  .picker-calendar-cell-content();

  .rs-calendar-table-cell-is-today & {
    box-shadow: inset 0 0 0 1px var(--rs-input-focus-border);
  }

  .rs-calendar-table-cell-selected & {
    .picker-calendar-cell-content-selected();
  }
}

// Table header row
.rs-calendar-table-header-cell-content {
  display: inline-block;
  color: var(--rs-text-secondary);
  font-size: @font-size-small;
  line-height: @line-height-small;
  padding-top: 2px;
  padding-bottom: 2px;

  &,
  &:hover,
  &:focus,
  &:hover:focus {
    background: none;
    cursor: auto;
  }
}

.rs-calendar-table-cell-week-number {
  display: table-cell;
  min-width: 30px;
  padding: @calendar-table-cell-padding;
  text-align: center;
  vertical-align: middle;
  color: var(--rs-text-secondary);
  background-color: var(--rs-bg-well);
  font-size: @font-size-small;
}

// Calendar month dropdown
.rs-calendar-month-dropdown {
  display: none;
  position: absolute;
  top: @calendar-dropdown-top;
  border-top: 1px solid var(--rs-border-primary);
  margin-top: 0;
  width: 100%;
  background-color: var(--rs-bg-overlay);
  overflow: hidden;
  z-index: @zindex-date-range-picker-table-cell-content;

  .rs-calendar-month-view & {
    display: block;
  }

  .rs-calendar-month-view &-content {
    animation: 0.3s linear slideDown;
  }

  &-scroll {
    height: 230px;
  }

  &-row {
    position: relative;
    padding-left: @calendar-picker-padding + 38px; // 30px for the year label + 8px gap
    padding-right: @calendar-picker-padding;
    padding-top: 5px;
    padding-bottom: 5px;

    &:not(:last-child) {
      border-bottom: 1px dashed var(--rs-border-primary);
    }
  }

  &-year {
    position: absolute;
    top: ~'calc(50% - 0.5em)';
    left: @calendar-picker-padding;

    &-active {
      color: var(--rs-text-active);
    }
  }

  &-list {
    display: block;
    min-width: 30px * 6 + 4px * 5;
    .clearfix();
  }

  &-cell {
    display: inline-block;
    float: left;
    width: ~'calc((100% - @{calendar-table-cell-content-today-border-width} * 12 ) / 6)';
    margin: 1px;
    text-align: center;
    vertical-align: middle;

    // In IE and Edge need more minus 1px. @see https://github.com/rsuite/rsuite/issues/585
    .ie11-edge-width(
      ~'calc((100% - @{calendar-table-cell-content-today-border-width} * 12 - 1px) / 6)'
    );
  }

  &-cell-content {
    .picker-calendar-cell-content();
    width: @calendar-in-menu-content-side-length;
    height: @calendar-in-menu-content-side-length;
  }

  &-cell:not(&-cell-active).disabled &-cell-content {
    color: var(--rs-text-disabled);
    background: none;
    text-decoration: line-through;
    cursor: not-allowed;
  }

  &-cell-active.disabled &-cell-content {
    opacity: 0.3;
    cursor: not-allowed;
  }

  &-cell-active &-cell-content {
    .picker-calendar-cell-content-selected();
  }
}

// Calendar time dropdown
.rs-calendar-time-dropdown {
  display: none;
  position: absolute;
  top: @calendar-dropdown-top;
  padding-left: @calendar-picker-padding;
  padding-right: @calendar-picker-padding;
  width: 100%;
  background-color: var(--rs-bg-overlay);
  color: var(--rs-text-primary);
  overflow: hidden;
  z-index: @zindex-date-range-picker-table-cell-content;

  .rs-calendar-time-view & {
    display: block;
  }

  .rs-calendar-time-view &-content {
    animation: 0.3s linear slideDown;
  }

  &-row {
    display: table;
    width: 100%;
  }

  &-column {
    display: table-cell;
    width: 1%;

    > ul,
    > ul > li {
      list-style: none;
      margin: 0;
      padding: 0;
    }

    > ul {
      height: 230px;
      overflow-y: auto;
      padding-bottom: 200px;
    }
  }

  &-column-title {
    width: 100%;
    background-color: var(--rs-calendar-time-unit-bg);
    color: var(--rs-text-secondary);
    text-align: center;
    font-size: @font-size-small;
    line-height: @line-height-small;
    padding-top: 2px;
    padding-bottom: 2px;
  }

  &-cell {
    font-size: @font-size-base;
    line-height: @line-height-computed;
    color: inherit;
    padding: 5px;
    display: block;
    text-align: center;
    cursor: pointer;

    &,
    &:hover,
    &:focus {
      text-decoration: none;
    }

    &:hover {
      .listbox-option-active();
    }

    &&-active {
      background-color: var(--rs-bg-active);
      color: var(--rs-calendar-date-selected-text);

      .high-contrast-mode({
        &:hover {
          .listbox-option-active();
        }
      });
    }

    &&-disabled {
      color: var(--rs-text-disabled);
      background: none;
      cursor: not-allowed;
      text-decoration: line-through;
    }

    &-active&-disabled& {
      opacity: 0.3;
      cursor: not-allowed;
    }
  }
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }

  to {
    transform: translateY(0);
  }
}
